package cn.school;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import cn.school.util.DBUtil;

public class MetaData {

	public static void main(String[] args) {
		Connection con = DBUtil.getConnection();
		try {
			DatabaseMetaData dbmeta = con.getMetaData();
			System.out.println(dbmeta.getDatabaseProductName());
			System.out.println(dbmeta.getDatabaseProductVersion());
			PreparedStatement ps = con.prepareStatement("select * from s_student");
			ResultSet rs = ps.executeQuery();
			ResultSetMetaData rm = rs.getMetaData();
			for (int i = 1; i <= rm.getColumnCount(); i++) {
				System.out.println(rm.getColumnLabel(i) + ":" + rm.getColumnTypeName(i) + ">对应的java类型:"
						+ rm.getColumnClassName(i));
			}

			DBUtil.close(rs, ps, con);
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}
